<?php

include_once("includes/Sigma.php");

$serverdb = "sussanboutique.no-ip.org";
$db = "erpsussan";
$userdb = "erpsussan";
$passdb = "loboferoz99";

$link = @mysql_connect($serverdb, $userdb, $passdb);
$result = @mysql_select_db($db, $link);

//COMPRAS
$query = "SELECT *
FROM (
`compras` c
JOIN compras_items ci ON c.idfactura = ci.idfactura
)
JOIN producto_talle_color ptc ON ci.codsussan = ptc.codsussan
AND ci.talle = ptc.talle
AND ci.color = ptc.color
WHERE c.idfactura LIKE '1-185'";

$result = mysql_query($query, $link);

while($f = mysql_fetch_array($result)){
	$q = "SELECT * FROM stock WHERE ptc = '".$f[id]."'";
	$result2 = mysql_query($q, $link);
	$stock = mysql_fetch_array($result2);
	$stock = $stock[stock];
	$nuevo_stock = $stock - $f[cantidad];
	echo "<br>";
	echo "UPDATE stock SET stock = ".$nuevo_stock." WHERE ptc = '".$f[id]."' AND sucursal = 1";
	//echo "<br>";
	//echo $f[cantidad];
}



?>